<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/jsp/inc/header.jsp" %>
<c:set var="title" value="手表"/>
<c:set var="rootpath" value="${CONTEXT_PATH}/admin/product/watch"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${STATIC_HOST}/css/ligerui.css" rel="stylesheet" type="text/css"/>
    <link href="${STATIC_HOST}/css/common.css" rel="stylesheet" type="text/css" />
    <script src="${STATIC_HOST}/js/common.js" type="text/javascript"></script>
    <script src="${STATIC_HOST}/js/LG.js" type="text/javascript"></script>
    <title>${title}管理</title>
</head>
<body class="listbody">

	<!-- 导航开始 -->
	<div class="withicon">
		<span><b>当前位置：内容 &gt; <a href="list.do?view=${view}">${title}管理</a></b></span>
	</div>
	<!-- 导航结束 -->
	
	<!-- 搜索开始 -->
	<div id="mainsearch" class="l-panel">
		<div class="searchtitle l-panel-topbar"><span>搜索</span><img src="${STATIC_HOST}/images/common/searchtool.gif"><div class="togglebtn"></div></div>
		<div class="searchbox">
		<form action="${rootpath}/list.do" method="post" name="searchForm" id="searchForm">
		<ul>
		   <li class="li_search_left"><label for="eqId">ID</label>：</li>
			   <li class="li_search_right">
			<input type="text" name="eqId" id="eqId" size="10" ltype='text' ligerui='{"width":100}'  value="${eqId}"/>
		  </li> 
		   <li class="li_search_left"><label for="likeName">手表名称</label>：</li>
			   <li class="li_search_right">
			<input type="text" name="likeName" id="likeName" size="10" ltype='text' ligerui='{"width":100}'  value="${likeName}"/>
		  </li>
			<li class="li_search_left"><label for="eqBrandId">品牌ID</label>：</li>
			<li class="li_search_right">
				<input type="text" name="eqBrandId" id="eqBrandId" size="10" ltype='text' ligerui='{"width":100}'  value="${eqBrandId}"/>
				<input value="选择" type="button" class="l-button ellipsis" style="min-width:50px;" onclick="f_select({'targetId':'eqBrandId','selectType':'/admin/product/cate','customParam':'&eqTypeId=5'})">
			</li>

			<li class="li_search_left"><label for="eqSex">性别</label>：</li>
			<li class="li_search_right">
				<select name="eqSex" id="eqSex" ltype="select" size="1" ligerui='{"width":100}'>
					<option value=""  <c:if test="${eqSex==''}">selected</c:if> >-全部-</option>
					<option value="1"  <c:if test="${eqSex==1}">selected</c:if> >男</option>
					<option value="2"  <c:if test="${eqSex==2}">selected</c:if> >女</option>
					<option value="0"  <c:if test="${eqSex==0}">selected</c:if> >不限</option>
				</select>
			</li>

			<li class="li_search_left"><label for="eqStatus">状态</label>：</li>
			<li class="li_search_right">
				<select name="eqStatus" id="eqStatus" ltype="select" size="1" ligerui='{"width":100}'>
					<option value=""  <c:if test="${eqStatus==''}">selected</c:if> >-全部-</option>
					<option value="1"  <c:if test="${eqStatus==1}">selected</c:if> >在售</option>
					<option value="0"  <c:if test="${eqStatus==0}">selected</c:if> >下架</option>
				</select>
			</li>

		<li class="li_searchbutton">
		  <div id="searchbutton" class="button button2 buttonnoicon">
			<div class="button-l"></div>
			<div class="button-r"></div>
			<span>搜索</span>
		  </div>
		  <div class="div_advsearchbutton"></div>
		  <div id="advsearchbutton">
			<span>更多搜索</span>
		  </div>
		</li>
		</ul>
	  </form>
	  </div>
	</div>
	<!-- 搜索结束 -->   
	
	<div class="div_newline"></div>
	
	<!-- 列表开始 -->
	<div id="maingrid"></div> 
	<!-- 列表结束 -->
	
	<script type="text/javascript">

		//推送到区块
		function push2region(){
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) {
				LG.tip('请选择要批量推送的行!');
				return "";
			}
			f_select({'selectType':'/admin/site/region','callback':'callbackRegion','customParam':'&eqStatus=1&inIds=22','gridMultiple':'1'});
		}

		function callbackRegion(jsonData){
			var data = JSON.parse(jsonData);
			var targetIds = "";
			for (i = 0; i < data.length; i++) {
				targetIds += ("," + data[i].id);
			}
			if (targetIds.length > 0) {
				targetIds = targetIds.substr(1);
			}

			var selecteds = grid.getSelecteds();
			var watchIds="";
			for(var key in selecteds){
				watchIds += (","+selecteds[key].id);
			}
			watchIds = watchIds.substring(1);

			jQuery.getJSON("${CONTEXT_PATH}/admin/product/watch/push.do?watchIds="+watchIds+"&targetIds="+targetIds,function(data){
				$.ligerDialog.alert("<li><b><i>成功推送:</i></b></li>手表id:"+watchIds+"<br/>目标id:"+targetIds+"<br/>", '批量推送的结果');
			});
		}

		//查看
		function show(id){
			jQuery("#view").val('/admin/product/watch/show');
			top.f_addTab(null, "查看手表", "${rootpath}/show.do?id="+id);
		}
		//编辑
		function edit(id){
			jQuery("#view").val('');
			top.f_addTab(null, "编辑手表", "${rootpath}/edit.do?id="+id);
		}
		//新建
		function newObject(){
			jQuery("#view").val('');
			top.f_addTab(null, "新建手表", "${rootpath}/edit.do");
		}
		//获取选择ID
		function getSelectedId(){
			var selecteds = grid.getSelecteds();
			if (selecteds.length==0) { 
				return "";
			}
			var ids="";
			for(var key in selecteds){
				ids += (","+selecteds[key].id);
			}
			return ids.substring(1);
		}
		//删除
		function del(id){
			var path = "${rootpath}/delete.do";
			if( !isNaN(id) ){
				path += "?eqId=" + id;
			}else{
				var ids = getSelectedId();
				if (ids.length==0) { 
					LG.tip('请选择要删除的行!'); 
					return;
				}
				path += "?inIds=" + ids;
			}
			$.ligerDialog.confirm("确定要删除吗？", function (yes) {
				if( yes ) submitReq(path);
			});
		}
		//批量删除
		function batchDelete(){
			del();
		}
		//无效
		function auditNotPass(){
			updateStatus( 0 );
		}
		//有效
		function auditPass(){
			updateStatus( 1 );
		}
		//更新状态
		function updateStatus(statusValue,id){
			var path = "${rootpath}/updateStatus.do?status="+statusValue;
			if( !isNaN(id) ){
				path += "&eqId=" + id;
			}else{
				var ids = getSelectedId();
				if (ids.length==0) { 
					LG.tip('请选择要更新的行!'); 
					return;
				}
				path += "&inIds=" + ids;
			}
			$.ligerDialog.confirm("确定要操作吗？", function (yes) {
				if( yes ) submitReq(path);
			});
		}
		//提交
		function submitReq(path,query,notsubmit){
			pageFormObj = document.pageForm;
			pageFormObj.action = path;
			if(query){
				pageFormObj.queryParam.value = query;
			}
			if(!notsubmit){
				pageFormObj.submit();
			}
			return false;
		}

		var statusMap	=	${jsonali:toJSONString(statusMap)};
	//列表
	var grid = $("#maingrid").ligerGrid({
		
      columns: [
        { display:"id", name:"id", align: 'left', width: 80, type: 'int', frozen: true, render: function(row){
              return "<a href='javascript:show("+row.id+")'>"+row.id+"</a>";
            }
         },
	  	{ display:"手表名称", name:"name", align: 'left', width: 250 , render: function(row){
			  return "<a target='_blank' href='http://www.qiaoliba.com/watch/pc/"+row.id+".shtml'>"+ row.name +"</a>";
		  }
	  	},
	  	{ display:"品牌", name:"brandName", align: 'left', width: 100 },
	    { display:"市场价", name:"marketPrice", align: 'left', width: 70 ,type: 'int'},
	    { display:"二手价", name:"secondPrice", align: 'left', width: 70 ,type: 'int'},
	    { display:"序号", name:"sortNum", align: 'left', width: 80 ,type: 'int', hide:true},
	  	{ display:"性别", name:"sex", align: 'left', width: 60 ,type: 'int', render: function(row){
				if(row.sex=='1'){
					return "男";
				}else if(row.sex=='2'){
					return "女";
				}else {
					return "不限";
				}
			}
		},
	  	{ display:"状态", name:"status", align: 'left', width: 80, type: 'int', render: function(row){
			  return "<span class='status" + row.status+"'>"+statusMap[row.status]+"</span>";
		  }
	  	},
	  	{ display:"修改时间", name:"modifyTime", align: 'left', width: 130 ,type: 'date' },
        { display:"操作", minWidth: 150, isAllowHide: false, isSort: false, render: function(row){
            return '<img src="http://static.21cnimg.com/img/icons/content/edit.gif" class="imgbtn" alt="修改" title="修改" onclick="edit('+row.id+')" />'
              +'<img src="http://static.21cnimg.com/img/icons/content/audit.gif" class="imgbtn" alt="上架" title="上架" onclick="updateStatus(1, '+row.id+')" />'
              +'<img src="http://static.21cnimg.com/img/icons/silkicons/delete.png" class="imgbtn" alt="下架" title="下架" onclick="updateStatus(0, '+row.id+')" />'
              +'<img src="http://static.21cnimg.com/img/icons/content/delete2.gif" class="imgbtn" alt="删除" title="删除" onclick="del('+row.id+')" />';
           }
         }
      ],
      parms: [ {name:'_ajax', value:1}
          <c:if test="${not empty eqId}">, { name:'eqId',value:'${eqId}'}</c:if>
          <c:if test="${not empty eqName}">, { name:'eqName',value:'${eqName}'}</c:if>
          <c:if test="${not empty eqNameShort}">, { name:'eqNameShort',value:'${eqNameShort}'}</c:if>
          <c:if test="${not empty eqMarketPrice}">, { name:'eqMarketPrice',value:'${eqMarketPrice}'}</c:if>
          <c:if test="${not empty eqSecondPrice}">, { name:'eqSecondPrice',value:'${eqSecondPrice}'}</c:if>
          <c:if test="${not empty eqKeyword}">, { name:'eqKeyword',value:'${eqKeyword}'}</c:if>
          <c:if test="${not empty eqFirstPicUrl}">, { name:'eqFirstPicUrl',value:'${eqFirstPicUrl}'}</c:if>
          <c:if test="${not empty eqDetails}">, { name:'eqDetails',value:'${eqDetails}'}</c:if>
          <c:if test="${not empty eqSortNum}">, { name:'eqSortNum',value:'${eqSortNum}'}</c:if>
          <c:if test="${not empty eqStatus}">, { name:'eqStatus',value:'${eqStatus}'}</c:if>
          <c:if test="${not empty eqClickNum}">, { name:'eqClickNum',value:'${eqClickNum}'}</c:if>
          <c:if test="${not empty eqShareNum}">, { name:'eqShareNum',value:'${eqShareNum}'}</c:if>
          <c:if test="${not empty eqGoodNum}">, { name:'eqGoodNum',value:'${eqGoodNum}'}</c:if>
          <c:if test="${not empty eqBadNum}">, { name:'eqBadNum',value:'${eqBadNum}'}</c:if>
          <c:if test="${not empty eqCreateUserId}">, { name:'eqCreateUserId',value:'${eqCreateUserId}'}</c:if>
          <c:if test="${not empty eqCreateTime}">, { name:'eqCreateTime',value:'${eqCreateTime}'}</c:if>
          <c:if test="${not empty eqModifyUserId}">, { name:'eqModifyUserId',value:'${eqModifyUserId}'}</c:if>
          <c:if test="${not empty eqModifyTime}">, { name:'eqModifyTime',value:'${eqModifyTime}'}</c:if>
         ] ,
		toolbar: { items: [
		         { line: true }
                ,{ text: '上架', click: auditPass, img: 'http://static.21cnimg.com/img/icons/silkicons/accept.png' }
                ,{ line: true }
                ,{ text: '下架', click: auditNotPass, img: 'http://static.21cnimg.com/img/icons/silkicons/delete.png' }
                ,{ line: true }
                ,{ text: '删除', click: batchDelete, img: 'http://static.21cnimg.com/img/icons/silkicons/cross.png' }
                ,{ line: true }
                ,{ text: '新增', click: newObject, img: 'http://static.21cnimg.com/img/icons/silkicons/add.png' }
                ,{ line: true }
				,{ text: '推送区块', click: push2region, img: 'http://static.21cnimg.com/img/icons/miniicons/list_extensions.gif' }
				,{ line: true }
			] },
	    pageSize: ${pageSize}, pageSizeOptions:[5,10,20,40,60,80,100],
	    pageParmName:'pageNo', pagesizeParmName:'pageSize', sortnameParmName:'sortName',sortorderParmName:'sortOrder',
	    dataAction:'server', 
	    url: '${rootpath}/search.do',
	    rownumbers: true, checkbox: true, frozen: true , dateFormat:'yyyy-MM-dd hh:mm',
		width: '98%', height: '100%', rowHeight:25, fixedCellHeight: true, usePager: true
	});
	
	jQuery("#searchbutton").click(function(){
	    var params = '';
        var group = {};
		var form=$("#searchForm");
        $(":input", form).not(":submit, :reset, :image,:button, [disabled]").each(function (){
            if (!this.name) return;
            if ($(this).val() == null || $(this).val() == "") return;
            var ltype = $(this).attr("ltype");
            var optionsJSON = $(this).attr("ligerui"), options;
            if (optionsJSON){
                options = JSON2.parse(optionsJSON);
            }
            //get the value type(number or date)
            var value = $(this).val();
            var name = this.name;
            //如果是下拉框，那么读取下拉框关联的隐藏控件的值(ID值,常用与外表关联)
            if (ltype == "select" && options && options.valueFieldID){
                value = $("#" + options.valueFieldID).val();
                name = options.valueFieldID;
            }
            group[name]=value;
			params += ("&"+name+"="+encodeURIComponent(value));
        });
	    grid.set('parms', group);
        grid.loadData();
        $("#queryParam").val( params.substring(1) );
	});
	
	jQuery("#advsearchbutton").click(function(){
	    jQuery("#advsearchdiv").slideToggle('fast');
	});
	
	$("#eqStatus").val('${eqStatus}');//初始化下来菜单
	$("#searchForm").ligerForm();
	
	</script>
	
	<form action="${rootpath}/list.do" method="post"  name="pageForm" id="pageForm">
	  <input type="hidden" id="queryParam" name="queryParam" value="${queryParam}"/>
	  <input name="view" id="view" type="hidden" value="${view}"/>
	</form>
	
	<%@ include file="/jsp/inc/footer.jsp"%>
</body>
</html>